<?php 
namespace Utuo;

class Rank {
	
	private $saeRank = null;
	
	private $config = array(
		'namespace' => '',
	);
	
	public function __construct( $cfg ) {
		$this->config = $cfg;
		$this->saeRank = new \SaeRank();
		$this->saeRank->create($this->config['namespace'], 2000);
	}
	
	public function increase( $key, $value = 1 ) {
		if ( false === $this->saeRank->increase($this->config['namespace'], $key, $value ) ) {
			return $this->set( $key, $value);
		}
		return true;
	}
	
	public function decrease( $key, $value = 1 ) {
		return $this->saeRank->decrease($this->config['namespace'], $key, $value );
	}
	
	public function getRank( $key ) {
		return $this->saeRank->getRank($this->config['namespace'], $key);
	}
	
	public function clear() {
		return $this->saeRank->clear($this->config['namespace']);
	}
	
	public function delete( $key ) {
		return $this->saeRank->delete($this->config['namespace'], $key);
	}
	
	public function set( $key, $value = 0 ) {
		return $this->saeRank->set($this->config['namespace'], $key, $value);
	}
	
	/**
	 * 返回值的形式：array（array（key，value) ....)
	 * @param string $order
	 * @param number $offsetFrom
	 * @param number $offsetTo
	 */
	public function getList( $order = false, $offsetFrom  = 0, $offsetTo = 0 ) {
		return $this->saeRank->getList( $this->config['namespace'], $order, $offsetFrom, $offsetTo );
	}
	
	public function getValue ( $key ) {
		return $this->saeRank->getValue( $this->config['namespace'], $key );
	}
	
}
